package com.cskaoyan.day16;

import java.util.Arrays;
import java.util.Random;

public class StringTest {
    public static void main(String[] args) {
        String[] str = getArras();
        System.out.println("排序前:");
        System.out.println(Arrays.toString(str));
        for (int i = 0; i < str.length - 1; i++) {
            for (int j = 0; j < str.length - 1 - i; j++) {
                if (str[j].compareToIgnoreCase(str[1 + j]) > 0) {
                    String temp = str[j];
                    str[j] = str[j + 1];
                    str[j + 1] = temp;
                }
            }
        }
        System.out.println("排序后:");
        System.out.println(Arrays.toString(str));
    }

    public static String[] getArras() {
        int numStrings = 8;
        int stringLength = 2;
        String[] str = new String[numStrings];
        String alphabet = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
        Random random = new Random();

        for (int i = 0; i < numStrings; i++) {
            StringBuilder sb = new StringBuilder(stringLength);
            for (int j = 0; j < stringLength; j++) {
                int index = random.nextInt(alphabet.length());
                char randomChar = alphabet.charAt(index);
                sb.append(randomChar);
            }
            str[i] = sb.toString();
        }

        return str;
    }

}
